/*******************************************************************************
 * Copyright (c) 2006 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.activitydiagram.tabbedproperties.section;

import org.eclipse.uml2.uml.AddStructuralFeatureValueAction;
import org.eclipse.uml2.uml.InputPin;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;

import com.cea.papyrus.core.filters.TypeFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * this class is used to display value of result of CreateObjectAction
 * @author Patrick Tessier
 */
public class AddStructuralFeatureValueActionSection extends AbstractSelectionElementSection{


	public AddStructuralFeatureValueActionSection() {
		super("Value ", new TypeFilter());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public NamedElement getReferencedElementToDisplay() {
		InputPin inputPin=((AddStructuralFeatureValueAction)getElement()).getValue();
		if (inputPin!=null){
			if (inputPin.getType()!=null){
				return inputPin.getType();
			}
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void removeReferencedElement() {
		((AddStructuralFeatureValueAction)getElement()).setValue(null);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Type){
			Type type = ((Type)element);
			InputPin pin= UMLFactory.eINSTANCE.createInputPin();
			pin.setType(type);
			pin.setName(type.getName().toLowerCase());
			((AddStructuralFeatureValueAction)getElement()).setValue(pin);
		}
	}
}